﻿/* Author: Lucas Lorentz Lara - 25/09/2008
*/

package common.degrafa.render.utils {
	public class SVGColor {
		private static  var colors:Object = {};
		colors["aliceblue"] = "#F0F8FF";
		colors["antiquewhite"] = "#FAEBD7";
		colors["aqua"] = "#00FFFF";
		colors["aquamarine"] = "#7FFFD4";
		colors["azure"] = "#F0FFFF";
		colors["beige"] = "#F5F5DC";
		colors["bisque"] = "#FFE4C4";
		colors["black"] = "#000000";
		colors["blanchedalmond"] = "#FFEBCD";
		colors["blue"] = "#0000FF";
		colors["blueviolet"] = "#8A2BE2";
		colors["brown"] = "#A52A2A";
		colors["burlywood"] = "#DEB887";
		colors["cadetblue"] = "#5F9EA0";
		colors["chartreuse"] = "#7FFF00";
		colors["chocolate"] = "#D2691E";
		colors["coral"] = "#FF7F50";
		colors["cornflowerblue"] = "#6495ED";
		colors["cornsilk"] = "#FFF8DC";
		colors["crimson"] = "#DC143C";
		colors["cyan"] = "#00FFFF";
		colors["darkblue"] = "#00008B";
		colors["darkcyan"] = "#008B8B";
		colors["darkgoldenrod"] = "#B8860B";
		colors["darkgray"] = "#A9A9A9";
		colors["darkgrey"] = "#A9A9A9";
		colors["darkgreen"] = "#006400";
		colors["darkkhaki"] = "#BDB76B";
		colors["darkmagenta"] = "#8B008B";
		colors["darkolivegreen"] = "#556B2F";
		colors["darkorange"] = "#FF8C00";
		colors["darkorchid"] = "#9932CC";
		colors["darkred"] = "#8B0000";
		colors["darksalmon"] = "#E9967A";
		colors["darkseagreen"] = "#8FBC8F";
		colors["darkslateblue"] = "#483D8B";
		colors["darkslategray"] = "#2F4F4F";
		colors["darkslategrey"] = "#2F4F4F";
		colors["darkturquoise"] = "#00CED1";
		colors["darkviolet"] = "#9400D3";
		colors["deeppink"] = "#FF1493";
		colors["deepskyblue"] = "#00BFFF";
		colors["dimgray"] = "#696969";
		colors["dimgrey"] = "#696969";
		colors["dodgerblue"] = "#1E90FF";
		colors["firebrick"] = "#B22222";
		colors["floralwhite"] = "#FFFAF0";
		colors["forestgreen"] = "#228B22";
		colors["fuchsia"] = "#FF00FF";
		colors["gainsboro"] = "#DCDCDC";
		colors["ghostwhite"] = "#F8F8FF";
		colors["gold"] = "#FFD700";
		colors["goldenrod"] = "#DAA520";
		colors["gray"] = "#808080";
		colors["grey"] = "#808080";
		colors["green"] = "#008000";
		colors["greenyellow"] = "#ADFF2F";
		colors["honeydew"] = "#F0FFF0";
		colors["hotpink"] = "#FF69B4";
		colors["indianred"] = " #CD5C5C";
		colors["indigo"] = " #4B0082";
		colors["ivory"] = "#FFFFF0";
		colors["khaki"] = "#F0E68C";
		colors["lavender"] = "#E6E6FA";
		colors["lavenderblush"] = "#FFF0F5";
		colors["lawngreen"] = "#7CFC00";
		colors["lemonchiffon"] = "#FFFACD";
		colors["lightblue"] = "#ADD8E6";
		colors["lightcoral"] = "#F08080";
		colors["lightcyan"] = "#E0FFFF";
		colors["lightgoldenrodyellow"] = "#FAFAD2";
		colors["lightgray"] = "#D3D3D3";
		colors["lightgrey"] = "#D3D3D3";
		colors["lightgreen"] = "#90EE90";
		colors["lightpink"] = "#FFB6C1";
		colors["lightsalmon"] = "#FFA07A";
		colors["lightseagreen"] = "#20B2AA";
		colors["lightskyblue"] = "#87CEFA";
		colors["lightslategray"] = "#778899";
		colors["lightslategrey"] = "#778899";
		colors["lightsteelblue"] = "#B0C4DE";
		colors["lightyellow"] = "#FFFFE0";
		colors["lime"] = "#00FF00";
		colors["limegreen"] = "#32CD32";
		colors["linen"] = "#FAF0E6";
		colors["magenta"] = "#FF00FF";
		colors["maroon"] = "#800000";
		colors["mediumaquamarine"] = "#66CDAA";
		colors["mediumblue"] = "#0000CD";
		colors["mediumorchid"] = "#BA55D3";
		colors["mediumpurple"] = "#9370D8";
		colors["mediumseagreen"] = "#3CB371";
		colors["mediumslateblue"] = "#7B68EE";
		colors["mediumspringgreen"] = "#00FA9A";
		colors["mediumturquoise"] = "#48D1CC";
		colors["mediumvioletred"] = "#C71585";
		colors["midnightblue"] = "#191970";
		colors["mintcream"] = "#F5FFFA";
		colors["mistyrose"] = "#FFE4E1";
		colors["moccasin"] = "#FFE4B5";
		colors["navajowhite"] = "#FFDEAD";
		colors["navy"] = "#000080";
		colors["oldlace"] = "#FDF5E6";
		colors["olive"] = "#808000";
		colors["olivedrab"] = "#6B8E23";
		colors["orange"] = "#FFA500";
		colors["orangered"] = "#FF4500";
		colors["orchid"] = "#DA70D6";
		colors["palegoldenrod"] = "#EEE8AA";
		colors["palegreen"] = "#98FB98";
		colors["paleturquoise"] = "#AFEEEE";
		colors["palevioletred"] = "#D87093";
		colors["papayawhip"] = "#FFEFD5";
		colors["peachpuff"] = "#FFDAB9";
		colors["peru"] = "#CD853F";
		colors["pink"] = "#FFC0CB";
		colors["plum"] = "#DDA0DD";
		colors["powderblue"] = "#B0E0E6";
		colors["purple"] = "#800080";
		colors["red"] = "#FF0000";
		colors["rosybrown"] = "#BC8F8F";
		colors["royalblue"] = "#4169E1";
		colors["saddlebrown"] = "#8B4513";
		colors["salmon"] = "#FA8072";
		colors["sandybrown"] = "#F4A460";
		colors["seagreen"] = "#2E8B57";
		colors["seashell"] = "#FFF5EE";
		colors["sienna"] = "#A0522D";
		colors["silver"] = "#C0C0C0";
		colors["skyblue"] = "#87CEEB";
		colors["slateblue"] = "#6A5ACD";
		colors["slategray"] = "#708090";
		colors["slategrey"] = "#708090";
		colors["snow"] = "#FFFAFA";
		colors["springgreen"] = "#00FF7F";
		colors["steelblue"] = "#4682B4";
		colors["tan"] = "#D2B48C";
		colors["teal"] = "#008080";
		colors["thistle"] = "#D8BFD8";
		colors["tomato"] = "#FF6347";
		colors["turquoise"] = "#40E0D0";
		colors["violet"] = "#EE82EE";
		colors["wheat"] = "#F5DEB3";
		colors["white"] = "#FFFFFF";
		colors["whitesmoke"] = "#F5F5F5";
		colors["yellow"] = "#FFFF00";
		colors["yellowgreen"] = "#9ACD32";


		public static function getColorByName(name:String):String {
			return colors[name.toLowerCase()];
		}
		
		public static function parseToInt(s:String):uint {
			if(s==null)
				return 0x000000;
				
			s = StringUtil.trim(s);
			
			if(s=="none" || s==""){
				return 0x000000;
			} else if(s.charAt(0)=="#") {
				s = s.substring(1);
				if(s.length<6)
					s = s.charAt(0)+s.charAt(0)+s.charAt(1)+s.charAt(1)+s.charAt(2)+s.charAt(2);
				return new Number("0x" + s);
			} else if(s.indexOf("(")>-1){
				s = StringUtil.rtrim(s,")");
				s = s.split("(")[1];
				var args:Array = SVGParser.parseArgsData(s);
				return Number(args[0])*256*256 + Number(args[1])*256 + Number(args[2]);
			} else {
				return parseToInt(getColorByName(s));
			}
		}
		
		//Used in another project, can be deleted.
		public static function flashToSVG(color:uint):String{
			var colorText:String = color.toString(16);
			while (colorText.length < 6) {
				colorText = "0" + colorText;
			}
			return "#"+colorText;
		}
	}
}